//
//  YijianfankuiViewController.m
//  tianjin
//
//  Created by 鞠超 on 16/8/12.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "YijianfankuiViewController.h"

@interface YijianfankuiViewController () <UIScrollViewDelegate, UITextFieldDelegate, UITextViewDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;
//
@property (nonatomic, strong) UITextField * text_mail;

@property (nonatomic, strong) UITextView * textView;
//占位
@property (nonatomic, strong) UILabel * lbl_1;
@property (nonatomic, strong) UILabel * lbl_2;

@end

@implementation YijianfankuiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    _topView.backgroundColor = [UIColor blackColor];
    
    _lblTitle.text = @"意见反馈";
    _lblTitle.textColor = [UIColor whiteColor];
    _lblTitle.font = [UIFont systemFontOfSize:19];
    
    UIImageView * image_return = [[UIImageView alloc] initWithFrame:CGRectMake(15, 32, 10, 20)];
    image_return.image = [UIImage imageNamed:@"zuofanhui@2x.png"];
    [_topView addSubview:image_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 20, 35, 44);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.scrollView.contentSize = CGSizeMake(0, SCREEN_HEIGHT - 60);
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
    
    //邮箱
    UIView * view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 55)];
    view_1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_1];
    
    UILabel * lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 17.5, 70, 20)];
    lbl_1.text = @"您的邮箱:";
    lbl_1.font = [UIFont systemFontOfSize:16];
    [view_1 addSubview:lbl_1];
    
    self.text_mail = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(lbl_1.frame) + 5, 17.5, SCREEN_WIDTH - CGRectGetMaxX(lbl_1.frame) - 15, 20)];
    self.text_mail.delegate = self;
    self.text_mail.placeholder = @"请输入您的邮箱";
    self.text_mail.clearButtonMode = UITextFieldViewModeAlways;
    self.text_mail.font = [UIFont systemFontOfSize:16];
    self.text_mail.returnKeyType = UIReturnKeyDone;
    [view_1 addSubview:self.text_mail];
    
    //
    self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(view_1.frame) + 10, SCREEN_WIDTH - 20, 200)];
    self.textView.backgroundColor = [UIColor whiteColor];
    self.textView.font = [UIFont systemFontOfSize:16];
    self.textView.delegate = self;
    [self.scrollView addSubview:self.textView];
    
    self.lbl_1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 7.5, 200, 20)];
    self.lbl_1.textColor = [UIColor grayColor];
    self.lbl_1.font = [UIFont systemFontOfSize:16];
    self.lbl_1.text = @"请在此填写您的意见/建议";
    [self.textView addSubview:self.lbl_1];
    
    self.lbl_2 = [[UILabel alloc] initWithFrame:CGRectMake(5, CGRectGetMaxY(self.lbl_1.frame) + 5, 260, 20)];
    self.lbl_2.textColor = [UIColor grayColor];
    self.lbl_2.font = [UIFont systemFontOfSize:16];
    self.lbl_2.text = @"反馈意见会第一时间发送到您的邮箱";
    [self.textView addSubview:self.lbl_2];
    
    UIButton * btn_tijiao = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_tijiao.frame = CGRectMake(15, CGRectGetMaxY(self.textView.frame) + 50, SCREEN_WIDTH - 30, 45);
    btn_tijiao.layer.cornerRadius = 5;
    btn_tijiao.backgroundColor = navi_bar_bg_color;
    [btn_tijiao setTitle:@"提交" forState:(UIControlStateNormal)];
    [btn_tijiao setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    btn_tijiao.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.scrollView addSubview:btn_tijiao];
    [btn_tijiao addTarget:self action:@selector(btn_tijiaoAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark - 点击提交
- (void )btn_tijiaoAction:(UIButton *)sender
{
    NSLog(@"点击提交");
    
    [self.text_mail resignFirstResponder];
    [self.textView resignFirstResponder];
    
    if([self.textView.text length] == 0)
    {
        self.lbl_1.hidden = NO;
        self.lbl_2.hidden = NO;
    }
    else
    {
        self.lbl_1.hidden = YES;
        self.lbl_2.hidden = YES;
    }
}

#pragma mark - textField代理
- (BOOL )textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    
    return YES;
}

#pragma mark - textview代理
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
{
    self.lbl_1.hidden = YES;
    self.lbl_2.hidden = YES;
    
    return YES;
}
#pragma mark - scrollView代理
- (void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.text_mail resignFirstResponder];
    [self.textView resignFirstResponder];
    
    if([self.textView.text length] == 0)
    {
        self.lbl_1.hidden = NO;
        self.lbl_2.hidden = NO;
    }
    else
    {
        self.lbl_1.hidden = YES;
        self.lbl_2.hidden = YES;
    }
}

- (void )touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.text_mail resignFirstResponder];
    [self.textView resignFirstResponder];
    
    if([self.textView.text length] == 0)
    {
        self.lbl_1.hidden = NO;
        self.lbl_2.hidden = NO;
    }
    else
    {
        self.lbl_1.hidden = YES;
        self.lbl_2.hidden = YES;
    }
}











@end
